﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using InstantNaukriDAL;
using System.Collections.Generic;
using System.IO;

public partial class JobseekerProfile_EditProfessionalDetails : System.Web.UI.Page
{
    int ProfileId = 0, UserId = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Session["UserId"] == null)
                Response.Redirect("Default.aspx");
            string roleid = "";
            clsUserLoginDAL objclsUserLoginDAL = new clsUserLoginDAL();
            if (Request.QueryString["roleid"] != null)
                roleid = clsEncryptionDecryption.Decrypt(Request.QueryString["roleid"].ToString());
            if (roleid == "4")
            {
                IN_TB_USER objIN_TB_USER = new IN_TB_USER();
                if (Session["UserId"] != null)
                    objIN_TB_USER = objclsUserLoginDAL.GetUserByID(Convert.ToInt32(Session["UserId"].ToString()));
                if (objIN_TB_USER != null)
                {
                    Session["UserId"] = objIN_TB_USER.ID;
                    dvAutority.Visible = true;
                    Fillddls();
                    FillResumeDetails(objIN_TB_USER.ID);
                }
            }
        }
    }

    private void Fillddls()
    {
        try
        {
            // Preferred Location
            clsCity objclsCity = new clsCity();
            List<IN_TB_CITY> objIN_TB_CITY = new List<IN_TB_CITY>();
            objIN_TB_CITY = objclsCity.GetAllCities();
            ddlPreferedLocation.Items.Clear();
            ddlPreferedLocation.AppendDataBoundItems = true;
            ddlPreferedLocation.DataTextField = "CITY";
            ddlPreferedLocation.DataValueField = "ID";
            ddlPreferedLocation.Items.Add("Select");
            ddlPreferedLocation.Items[0].Value = "0";
            ddlPreferedLocation.DataSource = objIN_TB_CITY;
            ddlPreferedLocation.DataBind();

            //Current Location

            objclsCity = new clsCity();
            objIN_TB_CITY = new List<IN_TB_CITY>();
            objIN_TB_CITY = objclsCity.GetAllCities();
            ddlcurrentLocation.Items.Clear();
            ddlcurrentLocation.AppendDataBoundItems = true;
            ddlcurrentLocation.DataTextField = "CITY";
            ddlcurrentLocation.DataValueField = "ID";
            ddlcurrentLocation.Items.Add("Select");
            ddlcurrentLocation.Items[0].Value = "0";
            ddlcurrentLocation.DataSource = objIN_TB_CITY;
            ddlcurrentLocation.DataBind();

            // Functional Area
            clsFunctionalAreaDAL objclsFunctionalAreaDAL = new clsFunctionalAreaDAL();
            List<IN_TB_FUNCTIONAL_AREA> objIN_TB_FUNCTIONAL_AREA = new List<IN_TB_FUNCTIONAL_AREA>();
            objIN_TB_FUNCTIONAL_AREA = objclsFunctionalAreaDAL.GetAllFunctionalAreas();
            ddlFuntionalArea.Items.Clear();
            ddlFuntionalArea.AppendDataBoundItems = true;
            ddlFuntionalArea.DataTextField = "FUNCTIONAL_AREA";
            ddlFuntionalArea.DataValueField = "ID";
            ddlFuntionalArea.Items.Add("Select");
            ddlFuntionalArea.Items[0].Value = "0";
            ddlFuntionalArea.DataSource = objIN_TB_FUNCTIONAL_AREA;
            ddlFuntionalArea.DataBind();

            // Total Experience
            ddlTotalExp.Items.Clear();
            ddlTotalExp.AppendDataBoundItems = true;
            ddlTotalExp.Items.Add("Select");
            ddlTotalExp.Items[0].Value = "0";
            for (int i = 1; i <= 30; i++)
            {
                ddlTotalExp.Items.Add(i.ToString());
                ddlTotalExp.Items[i].Value = i.ToString();
            }
            ddlTotalExp.DataBind();

        }
        catch (Exception ex)
        {
        }
    }

    protected void btnUpdateProfessionalDetails_Click(object sender, EventArgs e)
    {
        try
        {
            if (Session["UserId"] != null && ViewState["ResumeMasterId"] != null)
            {
                int rid = Convert.ToInt32(ViewState["ResumeMasterId"].ToString());
                clsResumeDAL objclsResumeDAL = new clsResumeDAL();
                IN_TB_RESUME_MST ibjIN_TB_RESUME_MST = new IN_TB_RESUME_MST();
                ibjIN_TB_RESUME_MST = objclsResumeDAL.GetResumeById(rid);
                ibjIN_TB_RESUME_MST.KEY_SKILLS = txtKeySkills.Text;
                ibjIN_TB_RESUME_MST.RESUME_HEADLINE = txtResumeheadline.Text;
                ibjIN_TB_RESUME_MST.RESUME_SUMMARY = txtResumeSummary.Text;
                ibjIN_TB_RESUME_MST.CTC = txtCTC.Text;
                ibjIN_TB_RESUME_MST.CURRENT_DESIGNATION = txtCurrentDesignation.Text;
                ibjIN_TB_RESUME_MST.CURRENT_COMPANY = txtCurrentCompany.Text;
                ibjIN_TB_RESUME_MST.PREFERRED_LOCATION = ddlPreferedLocation.SelectedValue;
                ibjIN_TB_RESUME_MST.CURRENT_LOCATION = Convert.ToInt32(ddlcurrentLocation.SelectedValue);
                ibjIN_TB_RESUME_MST.TOTAL_EXP = Convert.ToInt32(ddlTotalExp.SelectedValue);
                ibjIN_TB_RESUME_MST.FUNCTIONAL_AREA = Convert.ToInt32(ddlFuntionalArea.SelectedValue);
                ibjIN_TB_RESUME_MST.USER_ID = Convert.ToInt32(Session["UserId"]);
                if (fuResume.HasFile)
                {
                    // Saving User Resume
                    string CVPath = Server.MapPath("~/Resumes/");
                    DirectoryInfo objFileInfo = new DirectoryInfo(CVPath);
                    if (!objFileInfo.Exists)
                        objFileInfo.Create();
                    fuResume.SaveAs(CVPath + "/" + fuResume.FileName);
                    ibjIN_TB_RESUME_MST.RESUME_PATH = Convert.ToInt32(Session["UserId"]) + "/" + fuResume.FileName;
                }
                int resumeid = objclsResumeDAL.SaveResume(ibjIN_TB_RESUME_MST);
            }

            if (Request.QueryString["roleid"] != null && Session["UserId"] != null)
            {
                Response.Redirect("JobseekerPrieview.aspx?roleid=" + Request.QueryString["roleid"].ToString());
            }
            else
            {
                Session["RoleId"] = null;
                Response.Redirect("JobSeekerLogin.aspx");
            }
        }
        catch (Exception)
        {

            throw;
        }

    }

    protected void FillResumeDetails(int UserId)
    {
        try
        {
            clsResumeDAL objclsResumeDAL = new clsResumeDAL();
            IN_TB_RESUME_MST ibjIN_TB_RESUME_MST = new IN_TB_RESUME_MST();
            ibjIN_TB_RESUME_MST = objclsResumeDAL.GetResumeByUserId(UserId);
            if (ibjIN_TB_RESUME_MST != null)
            {
                ViewState["ResumeMasterId"] = ibjIN_TB_RESUME_MST.ID;
                txtKeySkills.Text = Convert.ToString(ibjIN_TB_RESUME_MST.KEY_SKILLS);
                txtResumeheadline.Text = Convert.ToString(ibjIN_TB_RESUME_MST.RESUME_HEADLINE);
                txtResumeSummary.Text = Convert.ToString(ibjIN_TB_RESUME_MST.RESUME_SUMMARY);
                txtCTC.Text = Convert.ToString(ibjIN_TB_RESUME_MST.CTC);
                txtCurrentCompany.Text = Convert.ToString(ibjIN_TB_RESUME_MST.CURRENT_COMPANY);
                txtCurrentDesignation.Text = Convert.ToString(ibjIN_TB_RESUME_MST.CURRENT_DESIGNATION);
                ddlPreferedLocation.SelectedValue = Convert.ToString(ibjIN_TB_RESUME_MST.PREFERRED_LOCATION);
                ddlcurrentLocation.SelectedValue = Convert.ToString(ibjIN_TB_RESUME_MST.CURRENT_LOCATION);
                ddlTotalExp.SelectedValue = Convert.ToString(ibjIN_TB_RESUME_MST.TOTAL_EXP);
                ddlFuntionalArea.SelectedValue = Convert.ToString(ibjIN_TB_RESUME_MST.FUNCTIONAL_AREA);
            }
        }
        catch (Exception)
        {

            throw;
        }
    }
}
